package com.sim.storage

import com.sim.serialport.library.seria.ext.hexStringToAscii
import com.sim.storage.enums.FieldCode

data class RequestMessageBean(
    var stx: String = "",
    var length: String = "",
    var messageHeader: RequestMessageHeader,
    var messageData: List<MessageData>?,
    var etx: String = "",
    var lrc: String = ""
) {
    override fun toString(): String {
        return "stx:${stx}, \n" +
                "length:$length, \n" +
                "messageHeader:${messageHeader.toString()}, \n" +
                "messageData:${messageData?.toString()}, \n" +
                "etx:$etx, \n" +
                "lrc:$lrc"

    }
}
data class ResponseMessageBean(var stx: String = "",
                               var length: String = "",
                               var messageHeader: ResponseMessageHeader,
                               var messageData: List<MessageData>?,
                               var etx: String = "",
                               var lrc: String = ""){
    override fun toString(): String {
        return "stx:${stx}, \n" +
                "length:$length, \n" +
                "messageHeader:${messageHeader.toString()}, \n" +
                "messageData:${messageData?.toString()}, \n" +
                "etx:$etx, \n" +
                "lrc:$lrc"

    }
}

data class RequestMessageHeader(val ecn: String, val functionCode: String, val versionCode: String, val rfu: String) {
    override fun toString(): String {
        return "\n{ \n " +
                "\t ecn:$ecn, \n" +
                "\t functionCode: $functionCode(asc:${functionCode.hexStringToAscii()}), \n" +
                "\t versionCode: $versionCode(asc:${versionCode.hexStringToAscii()}), \n" +
                "\t rfu:$rfu \n" +
                "}"
    }
}
data class ResponseMessageHeader(val ecn: String, val functionCode: String, val responseCode: String, val rfu: String) {
    override fun toString(): String {
        return "\n{ \n " +
                "\t ecn:$ecn, \n" +
                "\t functionCode: $functionCode(asc:${functionCode.hexStringToAscii()}), \n" +
                "\t responseCode: $responseCode(asc:${responseCode.hexStringToAscii()}), \n" +
                "\t rfu:$rfu \n" +
                "}"
    }
}


data class MessageData(val fieldCode: String, val fieldLength: String, val data: String) {
    override fun toString(): String {
        return "\n { \n " +
                "\t fieldCode: $fieldCode(asc:${fieldCode.hexStringToAscii()} : ${FieldCode.fromCode(fieldCode.hexStringToAscii())}), \n" +
                "\t fieldLength: $fieldLength, \n" +
                "\t data: $data(asc:${data.hexStringToAscii()}) \n" +
                "}"
    }
}
